package com.ruoyi.miaomiao.service.impl;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.ruoyi.miaomiao.mapper.FGoodsMapper;
import com.ruoyi.miaomiao.domain.FGoods;
import com.ruoyi.miaomiao.service.IFGoodsService;

/**
 * 商品Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-07-21
 */
@Service
public class FGoodsServiceImpl implements IFGoodsService 
{
    @Value("${server.port}")
    private int serverPort;

    @Autowired
    private FGoodsMapper fGoodsMapper;

    /**
     * 查询商品
     * 
     * @param goodsId 商品主键
     * @return 商品
     */
    @Override
    public FGoods selectFGoodsByGoodsId(Long goodsId)
    {
        return fGoodsMapper.selectFGoodsByGoodsId(goodsId);
    }

    @Override
    public List<FGoods> selectFGoodsListByIds(Long[] goodsIds) {
        return fGoodsMapper.selectFGoodsListByIds(goodsIds);
    }

    /**
     * 查询商品列表
     * 
     * @param fGoods 商品
     * @return 商品
     */
    @Override
    public List<FGoods> selectFGoodsList(FGoods fGoods)
    {
        return fGoodsMapper.selectFGoodsList(fGoods);
    }

    /**
     * 新增商品
     * 
     * @param fGoods 商品
     * @return 结果
     */
    @Override
    public int insertFGoods(FGoods fGoods)
    {
        fGoods.setCreateTime(DateUtils.getNowDate());
        return fGoodsMapper.insertFGoods(fGoods);
    }

    /**
     * 修改商品
     * 
     * @param fGoods 商品
     * @return 结果
     */
    @Override
    public int updateFGoods(FGoods fGoods)
    {
        fGoods.setUpdateTime(DateUtils.getNowDate());
        return fGoodsMapper.updateFGoods(fGoods);
    }

    /**
     * 批量删除商品
     * 
     * @param goodsIds 需要删除的商品主键
     * @return 结果
     */
    @Override
    public int deleteFGoodsByGoodsIds(Long[] goodsIds)
    {
        return fGoodsMapper.deleteFGoodsByGoodsIds(goodsIds);
    }

    /**
     * 删除商品信息
     * 
     * @param goodsId 商品主键
     * @return 结果
     */
    @Override
    public int deleteFGoodsByGoodsId(Long goodsId)
    {
        return fGoodsMapper.deleteFGoodsByGoodsId(goodsId);
    }

//    /**
//     * 调用本地图片以二进制流形式传给前端
//     */
//    @Override
//    public byte[] getBytesByStream(InputStream inputStream) {
//        byte[] bytes = new byte[1024];
//
//        int b;
//        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//        try {
//            while((b = inputStream.read(bytes)) != -1){
//
//                byteArrayOutputStream.write(bytes,0,b);
//            }
//            return byteArrayOutputStream.toByteArray();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//
}
